home *** CD-ROM | disk | FTP | other *** search
/ Workbench Design / WB Collection.iso / workbench werkzeuge / uhren & terminkalender / time / sunclock / source / timer.c < prev    next >
C/C++ Source or Header  |  1996-04-07  |  2KB  |  74 lines

  1. /*-------------------------------------------------------------------------
  2.     SunClock
  3.  
  4.     Amiga version by Mark Waggoner, 
  5.     waggoner@ichips.intel.com or wagnell@PDaXcess.techbook.com
  6.     December 1991
  7.  
  8.     Timer.c
  9.     Functions for dealing with the timer device
  10. -------------------------------------------------------------------------*/
  11. #include <functions.h>
  12. #include <devices/timer.h>
  13.  
  14. extern struct MsgPort        *Timer_Port;
  15. extern struct timerequest    Time_Request;
  16. extern    ULONG                TimerMask;
  17.  
  18. #define IOR                (struct IORequest *)
  19.  
  20. /*************** Close the message port and the timer device **************/
  21. void
  22. CloseTimer(void) {
  23.     if (Time_Request.tr_node.io_Message.mn_ReplyPort) {
  24.         AbortIO(IOR &Time_Request);
  25.         WaitIO(IOR &Time_Request);
  26.         CloseDevice(IOR &Time_Request);
  27.         Time_Request.tr_node.io_Message.mn_ReplyPort = NULL;
  28.     }
  29.     if (Timer_Port)     DeletePort(Timer_Port);
  30.     Timer_Port = NULL;
  31. }
  32.  
  33. /***************** Opens a message port and the timer device **************/
  34. int
  35. OpenTimer(ULONG sec,ULONG micro) {
  36.  
  37.     if ((Timer_Port = CreatePort(NULL,0)) == NULL)
  38.         return 0;
  39.     if (OpenDevice(TIMERNAME,UNIT_VBLANK,IOR &Time_Request,NULL) != NULL) {
  40.         DeletePort(Timer_Port);
  41.         Timer_Port = NULL;
  42.         return 0;
  43.     }
  44.  
  45.     Time_Request.tr_node.io_Message.mn_ReplyPort    = Timer_Port;
  46.     Time_Request.tr_node.io_Command                 = TR_ADDREQUEST;
  47.     Time_Request.tr_node.io_Flags                   = NULL;
  48.     Time_Request.tr_node.io_Error                   = NULL;
  49.     Time_Request.tr_time.tv_secs                    = sec;
  50.     Time_Request.tr_time.tv_micro                    = micro; 
  51.     SendIO(IOR &Time_Request);
  52.     TimerMask  = 1L<<Timer_Port->mp_SigBit;
  53.     return 1;
  54. }
  55. /************************** end of OpenTimer *******************************/
  56.  
  57. /***************** Sends another request to the timer if necessary ********/
  58. void
  59. ResetTimeReq (ULONG sec,ULONG micro) 
  60. {
  61.     if (GetMsg(Timer_Port)) {
  62.         Time_Request.tr_time.tv_secs = sec;
  63.         Time_Request.tr_time.tv_micro = micro;
  64.         SendIO(IOR &Time_Request);
  65.     }
  66. }
  67.  
  68. /***************** Abort the current Timer request **************/
  69. void
  70. AbortTimer(void)
  71. {
  72.     AbortIO(IOR &Time_Request);
  73. }
  74.